﻿///////////////////////////////////////////////////////////////////////////////
//
//  This source is part of the  "Managed Task Framework.NET Runtime"  (MTF.NET Runtime).
//
//
//  Copyright (c) 2011, Multicore Consulting Limited (UK)
//  All rights reserved.
//  http://www.multicoreconsulting.co.uk
//
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions
//  are met:
//
//  -  Redistributions of source code must retain the above copyright
//     notice, this list of conditions and the following disclaimer.
//  -  Redistributions in binary form must reproduce the above copyright
//     notice, this list of conditions and the following disclaimer in
//     the documentation and/or other materials provided with the
//     distribution.
//  -  Neither the name of Multicore Consulting Limited nor the names of
//     its contributors may be used to endorse or promote products
//     derived from this software without specific prior written
//     permission.
//
//  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
//  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
//  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
//  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
//  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
//  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
//  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
//  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
//  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
//  POSSIBILITY OF SUCH DAMAGE.
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MTFOrg.MTF.MTFCore
{
	/// <summary>
	/// Defines a fixed size array of events.
	/// </summary>
	public class EventArray : Event
	{
		/// <summary>
		/// Dictionary of all contained events.
		/// </summary>
		protected List<Event> m_Events;

		/// <summary>
		/// Retrieves an event with the specified key.
		/// </summary>
		/// <param name="key">Key used to index the event</param>
		/// <returns>Event with the specified key</returns>
		public Event this[int idx]
		{
			get { return m_Events[idx]; }
		}

		/// <summary>
		/// Returns all the events in the event dictionary.
		/// </summary>
		public Event[] Events
		{
			get
			{
				return m_Events.ToArray();
			}
			set
			{
				m_Events.Clear();
				m_Events.AddRange(value);
			}
		}

		/// <summary>
		/// Default constructor.
		/// </summary>
		public EventArray()
		{
			m_Events = new List<Event>();
		}

		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="size">Size of array to create</param>
		public EventArray(int size)
		{
			m_Events = new List<Event>(size);
		}

        /// <summary>
        /// Constructor that adds several events automatically.
        /// </summary>
        /// <param name="events">Events to add</param>
        public EventArray(Event[] events)
        {
            m_Events = new List<Event>(events);
        }

        /// <summary>
        /// Constructor that adds a single event automatically.
        /// </summary>
        /// <param name="events">Single event to add</param>
        public EventArray(Event eventToAdd)
        {
            m_Events = new List<Event>();
            m_Events.Add(eventToAdd);
        }

		/// <summary>
		/// Adds an event to the event array
		/// </summary>
		/// <param name="newEvent">Event to add to the array</param>
		public void Add(Event newEvent)
		{
			m_Events.Add(newEvent);
		}

        /// <summary>
        /// Converts an event to an event array.
        /// </summary>
        /// <returns>This event array, unchanged</returns>
        public EventArray ToEventArray()
        {
            return this;
        }
	}
}
